package rf.vir

import rf.vir.User
import grails.validation.Validateable

@Validateable
class LoginCommand {
	String email
	String password
	String type
	private u
	User getUser() {
		if(!u && email) {
			u = User.findByEmail(email)
		}
		return u
	}
	
	static constraints = {
		email blank:false, validator:{ val, obj ->
			if(!obj.user)
				"user.not.found"
			}
		password blank:false, validator:{ val, obj ->
			if(obj.user && obj.user.password != val)
				return "user.password.invalid"
		}
	}
}
